package com.ruoyi.web.controller.rhtx;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dj.domain.TCddw;
import com.ruoyi.dj.service.ITCddwService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/rhtx/cddw")
public class TCddwController extends BaseController
{
    @Autowired
    private ITCddwService tCddwService;

    /**
     * 查询联合 格于抽点单位列表
     */
    @PreAuthorize("@ss.hasPermi('system:cddw:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCddw tCddw)
    {
        startPage();
        List<TCddw> list = tCddwService.selectTCddwList(tCddw);
        return getDataTable(list);
    }

    /**
     * 导出联合 格于抽点单位列表
     */
    @PreAuthorize("@ss.hasPermi('system:cddw:export')")
    @Log(title = "联合 格于抽点单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCddw tCddw)
    {
        List<TCddw> list = tCddwService.selectTCddwList(tCddw);
        ExcelUtil<TCddw> util = new ExcelUtil<TCddw>(TCddw.class);
        util.exportExcel(response, list, "联合 格于抽点单位数据");
    }

    /**
     * 获取联合 格于抽点单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cddw:query')")
    @GetMapping(value = "/{bgCcdwId}")
    public AjaxResult getInfo(@PathVariable("bgCcdwId") Long bgCcdwId)
    {
        return success(tCddwService.selectTCddwByBgCcdwId(bgCcdwId));
    }

    /**
     * 新增联合 格于抽点单位
     */
    @PreAuthorize("@ss.hasPermi('system:cddw:add')")
    @Log(title = "联合 格于抽点单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCddw tCddw)
    {
        return toAjax(tCddwService.insertTCddw(tCddw));
    }

    /**
     * 修改联合 格于抽点单位
     */
    @PreAuthorize("@ss.hasPermi('system:cddw:edit')")
    @Log(title = "联合 格于抽点单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCddw tCddw)
    {
        return toAjax(tCddwService.updateTCddw(tCddw));
    }

    /**
     * 删除联合 格于抽点单位
     */
    @PreAuthorize("@ss.hasPermi('system:cddw:remove')")
    @Log(title = "联合 格于抽点单位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bgCcdwIds}")
    public AjaxResult remove(@PathVariable Long[] bgCcdwIds)
    {
        return toAjax(tCddwService.deleteTCddwByBgCcdwIds(bgCcdwIds));
    }
}